﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestPlatform.Core;
using Raven.Client;
using Raven.Client.Document;
using TestPlatform.Performer.RavenDB.Entities;
using Raven.Abstractions.Data;
using Raven.Client.Indexes;

namespace TestPlatform.Performer.RavenDB
{
    public class RavenDBInsertPerformer : BaseInsertPerformer
    {               
        public override string UnderlyinEngine { get { return "RavenDB"; } }

        public RavenDBInsertPerformer()
            : base(new RavenDBHelper())
        {

        }               

        protected override void InsertEntity()
        {            
            using (IDocumentSession s = RavenDBHelper.Store.OpenSession())
            {
                s.Store(new User
                {
                    Id = Guid.NewGuid(),
                    Login = Guid.NewGuid().ToString(),
                    Name = Guid.NewGuid().ToString(),
                    Posts = Enumerable.Range(0, TestConfig.InsertSubEntitiesCount)
                        .Select(i => new Post { Id = Guid.NewGuid(), Text = Guid.NewGuid().ToString() })
                        .ToList()
                });

                s.SaveChanges();
            }
        }       
    }
}
